package com.echo.register.hosp.controller;

import com.echo.register.common.result.Result;
import com.echo.register.hosp.service.DepartmentService;
import com.echo.register.hosp.service.HospitalService;
import com.echo.register.hosp.service.ScheduleService;
import com.echo.register.model.hosp.Hospital;
import com.echo.register.model.hosp.Schedule;
import com.echo.register.vo.hosp.DepartmentVo;
import com.echo.register.vo.hosp.HospitalQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @ClassName: HospitalController
 * @Package: com.echo.register.hosp.controller
 * @Description: 医院管理接口
 * @Author 谢同学
 * @Create 2023/12/21 11:26
 * @Version 1.0
 */
@Api(tags="医院管理接口")
@RestController
// @CrossOrigin
@RequestMapping("/admin/hosp/hospital")
public class HospitalController {

    @Autowired
    private HospitalService hospitalService;

    @Autowired
    private DepartmentService departmentService;

    @Autowired
    private ScheduleService scheduleService;

    @ApiOperation("分页查询医院")
    @GetMapping("{page}/{limit}")
    public Result<?> getHospital(@PathVariable Integer page,
                                 @PathVariable Integer limit,
                                 HospitalQueryVo hospitalQueryVo){
        return Result.ok(hospitalService.selectPage(page,limit,hospitalQueryVo));
    }
    @ApiOperation("更新医院状态")
    @GetMapping("updateStatus/{id}/{status}")
    public Result<?> updateStatus(@PathVariable String id,
                                  @PathVariable Integer status){
        hospitalService.updateStatus(id,status);
        return Result.ok();
    }

    @ApiOperation("查询医院详情")
    @GetMapping("/show/{hoscode}")
    public Result<Hospital> getHospital(@PathVariable String hoscode) {
        return Result.ok(hospitalService.getHospitalByHoscode(hoscode));
    }

    //根据医院编号，查询医院所有科室列表
    @ApiOperation("查询医院所有科室列表")
    @GetMapping("/getDeptList/{hoscode}")
    public Result<List<DepartmentVo>> getDeptByHoscode(@PathVariable String hoscode){
        return Result.ok(departmentService.findDeptTree(hoscode));
    }

    @ApiOperation("根据医院编号&科室编号分页查询排班数据")
    @GetMapping("/getScheduleRule/{page}/{limit}/{hoscode}/{depcode}")
    public Result<Map<String, Object>> getScheduleRule(@PathVariable Integer page,
                                                       @PathVariable Integer limit,
                                                       @PathVariable String hoscode,
                                                       @PathVariable String depcode) {
        Map<String, Object> map = scheduleService.getRuleSchedule(page, limit, hoscode, depcode);
        return Result.ok(map);
    }

    @ApiOperation(value = "查询排班详细信息")
    @GetMapping("/getScheduleDetail/{hoscode}/{depcode}/{workDate}")
    public Result getScheduleDetail( @PathVariable String hoscode,
                                     @PathVariable String depcode,
                                     @PathVariable String workDate){
        List<Schedule> scheduleList = scheduleService.getScheduleByHoscodeAndDepcodeAndWorkDate(hoscode, depcode, workDate);
        return Result.ok(scheduleList);
    }
}
